package engine.objects;

import java.awt.Rectangle;

import org.lwjgl.input.Mouse;

import engine.graphics.*; 

public abstract class BoundingBox extends Rectangle implements IRender{

	private static final long serialVersionUID = 1L;
	
	protected final int ORIGINAL_WIDTH, ORIGINAL_HEIGHT ; 
	
	protected Vertex2f[] vertices = new Vertex2f[4]; 

	public BoundingBox(int x, int y, int w, int h) {
		setBounds(x, y, w, h);
		this.ORIGINAL_WIDTH = w ; 
		this.ORIGINAL_HEIGHT = h ; 
	}

	public void setBounds(int x, int y, int w, int h) {
		super.setBounds(x, y, w, h);
		this.initVertices();
	}

	public Vertex2f[] getVertices(){
		return this.vertices; 
	}
	
	public boolean collidingWith(BoundingBox b) {
		return this.intersects(b);
	}
	public int getObjectWidth(){
		int x = (int) this.getMinX(); 
		return (int) (this.getMaxX() - x) ;
	}
	
	public int getObjectHeight(){
		int y = (int) this.getMinY(); 
		return (int) (this.getMaxY() - y) ;
	}

	public void initVertices(){
		vertices = new Vertex2f[]{
				new Vertex2f((float)getMinX(), (float)getMaxY()),
				new Vertex2f((float)getMaxX(), (float)getMaxY()),
				new Vertex2f((float)getMaxX(), (float)getMinY()),
				new Vertex2f((float)getMinX(), (float)getMinY())
		};
	}
	
	@Override
	public void update() { 
		initVertices(); 
	}
	
	public boolean contains(int x1, int x2, int y1, int y2){
		return (this.contains(x1,y1) || this.contains(x2, y1) || 
				this.contains(x1,y2) || this.contains(x2,y2)) ; 
	}
	
	public boolean MouseIn(){
		return this.contains(Mouse.getX(), Mouse.getY()) ; 
	}


	public void changeShape(int newX, int newY, int newWidth, int newHeight){
		this.setBounds(newX, newY, newWidth, newHeight); 
	}
	public void changeSize(int newWidth, int newHeight){
		this.changeShape((int)this.getX(), (int)this.getY(), newWidth, newHeight);
	}
	public void resizeX(int newWidth){
		this.changeSize(newWidth, this.getObjectHeight()); 
	}
	public void resizeY(int newHeight){
		this.changeSize(this.getObjectWidth(), newHeight); 
	}
	public void changeLocation(int newX, int newY){
		this.changeShape(newX, newY, this.getObjectWidth(), this.getObjectHeight()); 
	}
	public void changeLocationX(int newX){
		this.changeLocation(newX, (int)this.getY()); 
	}
	public void changeLocationY(int newY){
		this.changeLocation((int)this.getX(), newY); 
	}

	
}
